package com.dc.designPattern._2_factory._1_simplefactory.order;


import com.dc.designPattern._2_factory._1_simplefactory.pizza.CheesePizza;
import com.dc.designPattern._2_factory._1_simplefactory.pizza.GreekPizza;
import com.dc.designPattern._2_factory._1_simplefactory.pizza.PepperPizza;
import com.dc.designPattern._2_factory._1_simplefactory.pizza.Pizza;

/**
 * Description: 简单工厂类
 * @author: gdc
 * @date: 2021/3/7
 * @version 1.0
 */
public class SimpleFactory {

	/**
	 * 添加 orderType 返回对应的Pizza 对象
	 */
	public Pizza createPizza(String orderType) {
		System.out.println("使用简单工厂模式");

		Pizza pizza = null;
		if (orderType.equals("greek")) {
			pizza = new GreekPizza();
			pizza.setName(" 希腊披萨 ");
		} else if (orderType.equals("cheese")) {
			pizza = new CheesePizza();
			pizza.setName(" 奶酪披萨 ");
		} else if (orderType.equals("pepper")) {
			pizza = new PepperPizza();
			pizza.setName("胡椒披萨");
		}
		return pizza;
	}

	/**
	 * 简单工厂模式 也叫 静态工厂模式
	 */
	public static Pizza createPizza2(String orderType) {
		System.out.println("使用简单工厂模式2");

		Pizza pizza = null;
		if (orderType.equals("greek")) {
			pizza = new GreekPizza();
			pizza.setName(" 希腊披萨 ");
		} else if (orderType.equals("cheese")) {
			pizza = new CheesePizza();
			pizza.setName(" 奶酪披萨 ");
		} else if (orderType.equals("pepper")) {
			pizza = new PepperPizza();
			pizza.setName("胡椒披萨");
		}
		return pizza;
	}

}
